<?php
require_once("vcl/vcl.inc.php");
require_once("lib/db_connection.php");
//Includes
use_unit("components4phpfull/jtdivwindow.inc.php");
use_unit("components4phpfull/jtcategorybuttons.inc.php");
use_unit("components4phpfull/jtlabel.inc.php");
use_unit("components4phpfull/jtjavascript.inc.php");
use_unit("components4phpfull/jtpcregex.inc.php");
use_unit("components4phpfull/jtradiobuttonlist.inc.php");
use_unit("comctrls.inc.php");
use_unit("components4phpfull/jtgroupbox.inc.php");
use_unit("components4phpfull/jtsitetheme.inc.php");
use_unit("forms.inc.php");
use_unit("extctrls.inc.php");
use_unit("stdctrls.inc.php");

//Class definition
class CompanyWorkOrders extends Page
{
       public $JTGroupBox1 = null;
       public $Label4 = null;
       public $Label3 = null;
       public $Label2 = null;
       public $lblorder = null;
       public $hfError = null;
       public $JTDivInfo = null;
       public $JTGroupBox5 = null;
       public $Label13 = null;
       public $imgInfo = null;
       public $btnCancel = null;
       public $btnSubmit = null;
       public $chkAutoNumbering = null;
       public $edLastOrderNo = null;
       public $lblLastOrderNo = null;
       public $lblPrefix = null;
       public $edPrefix = null;
       public $lblAutoNumbering = null;
       public $Image3 = null;
       public $JTSiteTheme1 = null;
       function edLastOrderNoJSBlur($sender, $params)
       {

       ?>
       var edLastOrderNo = document.getElementById('edLastOrderNo').value;

       if(edLastOrderNo.length>0)
       {
       regex_pattern = "^[0-9]+$";
       var re = new RegExp(regex_pattern);
       var match = document.getElementById('edLastOrderNo').value.match(re);
       if(match==null)
       {
        document.getElementById('lblorder').innerHTML = "&darr;&nbsp;Pls. enter a number&nbsp;&darr;";
       }

       if(match!=null)
       {
        document.getElementById('lblorder').innerHTML = "";
       }
       }

       <?php

       }

       function imgInfoJSClick($sender, $params)
       {

       ?>
       //Add your javascript code here
       document.getElementById('JTDivInfo').Show();
       <?php

       }

       function cmbDefInvMarkupChange($sender, $params)
       {
       $markup=$this->cmbDefInvMarkup->getItemIndex();
       if ($markup=="Manual")
       {
       $this->edPrice->Enabled=false;
       }

       if ($markup=="Percent")
       {
       $this->edPrice->Enabled=true;
       }

       if ($markup=="Fixed Value")
       {
       $this->edPrice->Enabled=true;
       }


       }

       function rbtnDefInvMarkupJSChange($sender, $params)
       {

       ?>
       //Add your javascript code here
       if(document.CompanyWorkOrders.rbtnDefInvMarkupJSChange[1].checked==true)
       {
       document.CompanyWorkOrders.edPrice.disabled=false;
       }

       <?php

       }



       function btnCancelClick($sender, $params)
       {
       redirect('vehicle_list.php?company_id='.$_SESSION['company_id']);
       }

       function btnSubmitClick($sender, $params)
       {
       $orderno = $this->edLastOrderNo->Text;
       if($orderno!='')
       {
       if(!preg_match("/^[0-9]+$/",$this->edLastOrderNo->Text))
       {
        $this->lblorder->Caption = '&darr;&nbsp;Pls. enter a number&nbsp;&darr;';
        $this->hfError->setValue('1');
       }
       }

       $error = $this->hfError->getValue();
       if($error == '1' || $number != $key)
       {
          $this->hfError->setValue('0');
          return false;
       }
       else if($error == '0')
       {
        if ($this->chkAutoNumbering->Checked==true)
       {
       $chkAutoNumbering ='1';
       }
       else
       {
       $chkAutoNumbering='0';
       }

       /*if ($this->chkFavor->Checked==true)
       {
       $chkFavor='1';
       }
       else
       {
       $chkFavor='0';
       } */

       $result=mysql_query("select * from company_workorders_tbl where company_id='".$_SESSION['company_id']."'");
       $count=mysql_num_rows($result);
       if($count==0)
       {
       mysql_query("insert into company_workorders_tbl (company_id,
       auto_numbering,
       prefix,
       last_order_no)

       Values('".$_SESSION['company_id']."',
       '".$chkAutoNumbering."',
       '".$this->edPrefix->Text."',
       '".$this->edLastOrderNo->Text."')") or die ("insert workorders - " . mysql_error());
       }
       else
       {
       mysql_query("update company_workorders_tbl set
       auto_numbering='".$chkAutoNumbering."',
       prefix='".$this->edPrefix->Text."',
       last_order_no='".$this->edLastOrderNo->Text."'
       where company_id='".$_SESSION['company_id']."'") or die ("update workorders - " . mysql_error());
       }
        redirect('vehicle_list.php?company_id='.$_SESSION['company_id']);
       }
       }


       function CompanyWorkOrdersCreate($sender, $params)
       {
       $this->hfError->setValue('0');
       $this->lblorder->Caption='';
       $query = "select * from company_workorders_tbl where company_id='".$_SESSION['company_id']."'";
       $result_show = mysql_query($query)or die("SELECT WORKORDERS- " . mysql_error());
       $row= mysql_fetch_array($result_show);

       if($row['auto_numbering']=='1')
       {
       $this->chkAutoNumbering->Checked=true;
       }
       else
       {
       $this->chkAutoNumbering->Checked=false;
       }



       //$this->cmbType->ItemIndex = $row['type'];
       //$this->rbtnDefInvExpensing->ItemIndex = $row['default_inv_expense'];
       //$this->cmbDefInvMarkup->ItemIndex = $row['default_inv_markup'];
       $this->edPrefix->Text = $row['prefix'];
       $this->edLastOrderNo->Text = $row['last_order_no'];
       //$this->edDefaultCharge->Text = $row['default_charge'];
       //$this->edDays->Text = $row['days'];
       //$this->edExceptFor->Text = $row['except_for'];
       //$this->edPrice->Text = $row['price'];

       //$this->edPrefix->Enabled=false;
       //$this->edLastOrderNo->Enabled=false;
       //$this->edPrice->Enabled=false;
       }

       function chkAutoNumberingJSChange($sender, $params)
       {

       ?>
       //Add your javascript code here
       if(document.CompanyWorkOrders.chkAutoNumbering.checked==true)
       {
       document.CompanyWorkOrders.edPrefix.disabled=false;
       document.CompanyWorkOrders.edLastOrderNo.disabled=false;
       }
       else
       {
       document.CompanyWorkOrders.edPrefix.disabled=true;
       document.CompanyWorkOrders.edLastOrderNo.disabled=true;
       }
       <?php

       }


}

global $application;

global $CompanyWorkOrders;

//Creates the form
$CompanyWorkOrders=new CompanyWorkOrders($application);

//Read from resource file
$CompanyWorkOrders->loadResource(__FILE__);

//Shows the form
$CompanyWorkOrders->show();

?>